package net.hn.hnms.biz.energy.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import net.hn.hnms.biz.energy.domain.WaterPlacePrice;
import net.hn.hnms.biz.energy.request.WaterPlacePriceReq;
import net.hn.hnms.biz.energy.vo.WaterPlacePriceVo;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;

public interface WaterPlacePriceMapper extends BaseMapper<WaterPlacePrice> {
    @Update("<script>" +
            " update  water_place_price set  del_flag = '1' " +
            " where water_place_id in" +
            " <foreach collection=\"list\" item=\"value\" separator=\",\" open=\"(\" close=\")\">\n" +
            "#{value}" +
            "</foreach>" +
            "</script>")
    void updateDeleteByIds(@Param("list") List<String> list);

    @Select("<script>" +
            " select wpp.water_supply_company_id waterSupplyCompanyId,wpp.water_place_id waterPlaceId,wpp.water_place_name waterPlaceName, wpp.water_unit_price waterUnitPrice," +
            " wsc.water_supply_company_name waterSupplyCompanyName,wpp.create_time createTime,wpp.water_unit_category from water_place_price wpp " +
            " LEFT JOIN water_supply_company wsc on wpp.water_supply_company_id = wsc.water_supply_company_id " +
            " where wpp.del_flag = '0'  " +
            " <if test='query.waterPlaceName != null and query.waterPlaceName != \"\" '> "+
            " and wpp.water_place_name LIKE CONCAT('%', #{query.waterPlaceName}, '%')  " +
            " </if>"+
            " <if test='query.mineCode != null and query.mineCode != \"\" '> "+
            " and wpp.mine_code = #{query.mineCode} " +
            " </if>"+
            " order by wpp.create_time desc </script>")
    Page<WaterPlacePriceVo> selectPageList(Page<Object> build, @Param("query") WaterPlacePriceReq waterPlacePriceReq);

    @Select("<script>select count(1)  from water_place_price where mine_code=#{mineCode} and del_flag='0'</script>")
    int getWaterPlacePriceByMineCode(@Param("mineCode") String mineCode);

}
